package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.agent.utils.AuthUtil;
import cn.com.chengmandian.bike.model.EbCsPeriod;
import cn.com.chengmandian.bike.mapper.EbCsPeriodMapper;
import cn.com.chengmandian.bike.model.EbMemberInfo;
import cn.com.chengmandian.bike.model.vo.CsPeriodInfoVo;
import cn.com.chengmandian.bike.service.IEbCsPeriodService;
import cn.com.chengmandian.bike.service.IEbMemberInfoService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 电单车运营-客户服务时段表 服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-11-19
 */
@Service
public class EbCsPeriodServiceImpl extends ServiceImpl<EbCsPeriodMapper, EbCsPeriod> implements IEbCsPeriodService {

    @Autowired
    private IEbMemberInfoService memberInfoService;

    @Override
    public CsPeriodInfoVo service(Integer areaId) {
        String timePeriod = DateUtil.format(DateUtil.date(), "HH:mm");
        CsPeriodInfoVo vo = baseMapper.service(areaId, timePeriod);
        if(AuthUtil.getAgentUser() != null && vo != null && StrUtil.isNotBlank(vo.getServiceLink())) {
            if(vo.getServiceLink().indexOf("chengmandian.com.cn") >= 0) {
                EbMemberInfo memberInfo = memberInfoService.getById(AuthUtil.getAgentUser().getId());
                if(memberInfo != null) {
                    String serviceLink = vo.getServiceLink().concat("&phone=" + memberInfo.getMobile());
                    vo.setServiceLink(serviceLink);
                }
            }
        }
        return vo;
    }
}
